package com.jame.basics.queue;

import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author : Jame
 * @date : 2021-07-10 11:42
 **/
public class Demo {

    public void test1(){
        Queue queue=new LinkedList();
        System.out.println(queue.add(new Object()));
        System.out.println(queue.remove());
        System.out.println(queue.poll());
    }

    public void test2(){
        Queue queue=new ArrayBlockingQueue<String>(10);
        for (int i = 0; i < 10; i++) {
            queue.offer(""+i);
        }

        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    System.out.println("删除是否成功"+queue.poll()+"B");
                    TimeUnit.MILLISECONDS.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();


        new Thread(() -> {
            for (int i = 0; i < 10; i++) {

                System.out.println("删除是否成功"+queue.poll()+"A");
                try {
                    TimeUnit.MILLISECONDS.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {

                System.out.println("删除是否成功"+queue.poll()+"C");
                try {
                    TimeUnit.MILLISECONDS.sleep(1100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }

    public static void main(String[] args) throws InterruptedException {
        Demo demo = new Demo();
        demo.test2();
    }
}
